<template>
  <div class="app-container">
  <div class="filter-container">
        <el-input clearable v-model="search.number" placeholder="合同号" style="width: 170px;margin-left:0px;"></el-input>
        <el-input clearable v-model="search.name" placeholder="销售顾问" style="width: 170px;margin-left:10px;"></el-input>
        <el-input clearable v-model="search.name" placeholder="具体车型" style="width: 170px;margin-left:10px;"></el-input>
        <el-date-picker v-model="search.daterange" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="margin-left:10px;">
        </el-date-picker>

        <el-button type="primary" icon="el-icon-search" @click="searchClick()" style="margin-left:10px;">查询</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" 
      border fit highlight-current-row stripe 
      style="width: 100%">
      <el-table-column align="center" label="序" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row._id }}</span>
        </template>
      </el-table-column>
     <el-table-column  min-width="100" align="center" label="订单合同号">
        <template slot-scope="scope">
          <span>{{ scope.row.ordernumber }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="客户名称">
        <template slot-scope="scope">
          <span>{{ scope.row.customername }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="具体车型">
        <template slot-scope="scope">
          <span>{{ scope.row.carname }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="已配车VIN码">
        <template slot-scope="scope">
          <span>{{ scope.row.vincode }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="销售顾问">
        <template slot-scope="scope">
          <span>{{ scope.row.guider }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="仓库名称">
        <template slot-scope="scope">
          <span>{{ scope.row.storename }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="仓位名称">
        <template slot-scope="scope">
          <span>{{ scope.row.storeplace }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="加装">
        <template slot-scope="scope">
          <span>{{ scope.row.extrastate }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="上牌">
        <template slot-scope="scope">
          <span>{{ scope.row.licensestate }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="状态">
        <template slot-scope="scope">
          <span>{{ scope.row.state | parseState }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="日期">
        <template slot-scope="scope">
          <span>{{ scope.row.createtime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      
      <el-table-column align="center" label="操作"  width="320" fixed="right">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="tableRowClick().operation(scope.row.id,1)">上牌借出</el-button>
          <el-button type="primary" size="small" @click="tableRowClick().operation(scope.row.id,2)">上牌归还</el-button>
          <el-button type="primary" size="small" @click="tableRowClick().operation(scope.row.id,3)">加装借出</el-button>
          <el-button type="primary" size="small" @click="tableRowClick().operation(scope.row.id,4)">加装归还</el-button>
          <el-button type="primary" size="small" @click="tableRowClick().operation(scope.row.id,5)">提出车库</el-button>
          <el-button type="primary" size="small" @click="tableRowClick().details(scope.row.id)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.rows" @pagination="fetchData" />

<!-- 借出/归还/提车 -->
<el-dialog :title="dialogLicense.title" :visible.sync="dialogLicense.visible"  width="900px">
    <div class="ci">
      <div class="item">
          <span class="name">销售合同号：</span>
          <span class="value">
              {{dialogLicense.data.ordernumber}}
          </span>
      </div>
      <div class="item">
          <span class="name">具体车型：</span>
          <span class="value">
              {{dialogLicense.data.carname}}
          </span>
      </div>
      <div class="item">
          <span class="name">VIN码：</span>
          <span class="value">
              {{dialogLicense.data.vincode}}
          </span>
      </div>
      <div class="item"  v-show="dialogLicense.type==2">
          <span class="name">上牌人员：</span>
          <span class="value">
              {{dialogLicense.data.guider}}
          </span>
      </div>
      <div class="item" v-show="[1,3,5].indexOf(dialogLicense.type)>-1">
          <span class="name">仓库名称：</span>
          <span class="value">
              {{dialogLicense.data.storename}}
          </span>
          <span class="name">仓位名称：</span>
          <span class="value">
              {{dialogLicense.data.storeplace}}
          </span>
      </div>
      <div class="item"  v-show="dialogLicense.type==1">
          <span class="name">上牌人员：</span>
          <span class="value">
              <el-input  v-model="dialogLicense.data.guider" placeholder="" style="width:220px;" ></el-input>
          </span>
      </div>
      <div class="item" v-show="[2,4].indexOf(dialogLicense.type)>-1">
          <span class="name">仓库名称</span>
          <span class="value">
              <el-input  v-model="dialogLicense.data.storename" placeholder="" style="width:220px;" ></el-input>
          </span>
          <span class="name">仓位名称</span>
          <span class="value">
              <el-input  v-model="dialogLicense.data.storeplace" placeholder="" style="width:220px;" ></el-input>
          </span>
      </div>
       <div class="item" v-show="[5].indexOf(dialogLicense.type)>-1">
          <span class="name">提车人</span>
          <span class="value">
              <el-input  v-model="dialogLicense.data.pickupparson" placeholder="" style="width:220px;" ></el-input>
          </span>
          <span class="name">提车单号</span>
          <span class="value">
              <el-input  v-model="dialogLicense.data.pickupnumber" placeholder="" style="width:220px;" ></el-input>
          </span>
      </div>

      
    </div>
    <div slot="footer" class="dialog-footer">
        <el-button @click="dialogLicense.visible = false">取 消</el-button>
        <el-button type="primary" @click="dialogLicenseClick().save()" :loading="dialogLicense.saveloading">保 存</el-button>
    </div>
</el-dialog>
<!-- end  借出/归还/提车 -->



  </div>
</template>

<script>
import * as carPurchaseApi from '@/api/cars/purchase'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import * as enumHelper from '@/utils/enum'
import {objectMerge,objectEmpty} from '@/utils/index'

export default {
    components: { Pagination },
    data(){
        return{
          search:{ 
              number:'',
              customer:'',
              phone:'',
              daterange:'',
          },
          listQuery: {
                page: 1,
                rows: 20,
                name:'',
                phone:'',
                state:-1,
                daterange:''
          },
          list:null,
          listLoading:false,
          total:0,
          selectOptions:{
            carinfo:[],
          },

          dialogLicense:{
              visible:false,
              saveloading:false,
              title:'上牌借出/归还',
              type:1,
              data:{
                  id:'',
                  ordernumber:'',
                  carname:'',
                  systemvincode:'',
                  purchasenumber:'',
                  carinfo:'',
                  carname:'',
                  vincode:'',
                  storename:'',
                  storeplace:'',
              }
          },
          dialogExtra:{
              visible:false,
              saveloading:false,
              title:'加装借出/归还',
              type:1,
              data:{
                  id:'',
                  ordernumber:'',
                  carname:'',
                  systemvincode:'',
                  purchasenumber:'',
                  carinfo:'',
                  carname:'',
                  vincode:'',
                  storename:'',
                  storeplace:'',
              }
          },
          
        }
    },
    created(){
        var that=this;
        //初始化下拉菜单
        //enumHelper.initOptions(that.selectOptions.purchasetype,enumHelper.cars.purchaseType);
        //enumHelper.initOptions(that.selectOptions.paystage,enumHelper.cars.payStage);
        that.fetchData();
    },
    filters:{

      parseState(val){
        return enumHelper.cars.distributeState.getName(val);
      }

    },
    methods:{
        fetchData(){
          var that=this;
            carPurchaseApi.getDistributeAfterList({}).then(res=>{
              if(res.data){
                that.list=[...res.data.items.map((item,index)=>{
                  item._id=index+1;
                  return item;
                })];
              }
            })
        },

        tableRowClick(){
          var that=this;
          var titles=['','上牌借出','上牌归还','加装借出','加装归还','提车出库',''];
          return {
            operation(id,type){
              var data=that.list.filter(o=>id==id)[0];
              that.dialogLicenseClick().init(data);
              that.dialogLicense.type=type;
              that.dialogLicense.title=titles[type];
              that.dialogLicense.visible=true;
            },

            details(id){
                that.$router.push({
                    path:'/cars/caroutstoredetails/'+id
                })
            }
          }
        },
        dialogLicenseClick(){
          var that=this;
          var dg=that.dialogLicense;
          return{
            init(data){
              data?objectMerge(dg.data,data):objectEmpty(dg.data);
            },
            save(){
              dg.visible=false;
            }
          }
        },
        
    }
}
</script>

<style scoped>

</style>